package cn.tedu.classx;
/*
    类中可以定义的内容：属性 方法  构造方法 构造代码块
 */
public class Teacher {
    String name;
    int age;
    //构造代码块 -- 初始化类的属性
    {
        System.out.println("这是构造代码块");
        age = 19;
    }
    //构造方法
//    public Teacher(){
//        System.out.println("hello");
//        this.name = "张三";
//       // this.age = 19;
//        System.out.println("无参构造");
//    }

    public Teacher() {}

    //有参构造
    public Teacher(String name){
        System.out.println("hello");
        this.name = name;
        //this.age = 19;
        System.out.println("有参构造");
    }
    public Teacher(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void teach(){
        //局部代码块
        {
            System.out.println("局部代码块");
            int num = 5;
            System.out.println(num);
        }
        //System.out.println(num);//编译报错
        System.out.println("讲课~~");
    }

    public void setTeacher(Teacher teacher){
        teacher.teach();
    }
    public Teacher getTeacher(){
//        Teacher t =  new Teacher();
//        return t;
        return new Teacher();
    }
}
